package strategy;

import java.math.BigDecimal;

public class PriceUtil {

  //充足金额
  public static boolean sufficientPrice(BigDecimal price, BigDecimal cost) {
    return price.compareTo(cost) > 0;
  }

  //费用结算
  public static BigDecimal settlement(BigDecimal price, BigDecimal cost, Integer code) {
    if (BuyOrSendEnum.BUY.getCode().equals(code)) {
      price = price.subtract(cost);
    } else {
      price = price.add(cost);
    }
    price = handingFee(price);
    return price;
  }

  //手续费结算
  public static BigDecimal handingFee(BigDecimal price) {
    BigDecimal fee = price.multiply(new BigDecimal("0.0002"));
    if (fee.compareTo(new BigDecimal(5)) < 0) {
      fee = new BigDecimal(5);
    }
    return price.subtract(fee);
  }

  //结算组合
  public static BigDecimal combination(BigDecimal price, BigDecimal cost, Integer code) {
    if (BuyOrSendEnum.BUY.getCode().equals(code)) {
      if (sufficientPrice(price, cost)) {
        price = settlement(price, cost, code);
      }
    } else {
      price = settlement(price, cost, code);
    }

    return price;
  }


}
